<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE root PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jstl/core">

	<div class="innerTitle">Lista de Veiculos (<h:outputText value="total:#{veiculoBean.entitiesSize}"/>)</div>

	<h:panelGroup styleClass="innerFilter" layout="block">

		<div class="innerTextFilter">Filtro</div>

		<h:inputText value="#{veiculoBean.filter}"></h:inputText>

		<a4j:commandButton value="Pesquisar" action="#{veiculoBean.search}" styleClass="button" reRender="popup"/>

		<a4j:commandButton value="Novo" action="#{veiculoBean.prepareSave}" styleClass="button" rendered="#{controlBean.administradorSistema}"  reRender="popup"/>

		<rich:dataTable id="listaVeiculo" rowClasses="even,odd" value="#{veiculoBean.entities}" var="veiculo" rows="10">

			<c:if test="#{controlBean.administradorSistema}">
				<rich:column sortBy="#{veiculo.codigoExterno}">
					<f:facet name="header"><h:outputLabel value="Cod Externo"/></f:facet>
					<h:outputText value="#{veiculo.codigoExterno}"/>
				</rich:column>

				<rich:column sortBy="#{veiculo.numeroSerial}">
					<f:facet name="header"><h:outputLabel value="Serial"/></f:facet>
					<h:outputText value="#{veiculo.numeroSerial}"/>
				</rich:column>
			</c:if>

			<rich:column sortBy="#{veiculo.nome}">
				<f:facet name="header"><h:outputLabel value="Descrição"/></f:facet>
				<h:outputText value="#{veiculo.nome}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.placa}">
				<f:facet name="header"><h:outputLabel value="Placa"/></f:facet>
				<h:outputText value="#{veiculo.placa}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.tipoVeiculoId.descricao}">
				<f:facet name="header"><h:outputLabel value="Tipo Veiculo"/></f:facet>
				<h:outputText value="#{veiculo.tipoVeiculoId.descricao}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.marcaId.descricao}">
				<f:facet name="header"><h:outputLabel value="Marca"/></f:facet>
				<h:outputText value="#{veiculo.marcaId.descricao}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.modeloId.descricao}">
				<f:facet name="header"><h:outputLabel value="Modelo"/></f:facet>
				<h:outputText value="#{veiculo.modeloId.descricao}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.combustivelId.descricao}">
				<f:facet name="header"><h:outputLabel value="Combustivel"/></f:facet>
				<h:outputText value="#{veiculo.combustivelId.descricao}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.ano}">
				<f:facet name="header"><h:outputLabel value="Ano"/></f:facet>
				<h:outputText value="#{veiculo.ano}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.cor}">
				<f:facet name="header"><h:outputLabel value="Cor"/></f:facet>
				<h:outputText value="#{veiculo.cor}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.responsavel.nome}">
				<f:facet name="header"><h:outputLabel value="Motorista"/></f:facet>
				<h:outputText value="#{veiculo.responsavel.nome}"/>
			</rich:column>

			<rich:column sortBy="#{veiculo.cliente.nome}" rendered="#{controlBean.administradorSistema}">
				<f:facet name="header"><h:outputLabel value="Cliente"/></f:facet>
				<h:outputText value="#{veiculo.cliente.nome}"/>
			</rich:column>

			<rich:column headerClass="link">
				<a4j:commandLink action="#{veiculoBean.prepareUpdate}" reRender="popup">
					<h:graphicImage styleClass="link" alt="Alterar" url="/images/btn/update.png"/>
					<f:setPropertyActionListener target="#{veiculoBean.entity}" value="#{veiculo}"/>
				</a4j:commandLink>
			</rich:column>

			<rich:column headerClass="link" rendered="#{controlBean.administradorSistema}">
				<a4j:commandLink action="#{veiculoBean.prepareDelete}" reRender="popup">
					<h:graphicImage styleClass="link" alt="Excluir" url="/images/btn/delete.png"/>
					<f:setPropertyActionListener target="#{veiculoBean.entity}" value="#{veiculo}"/>
				</a4j:commandLink>
			</rich:column>

            <f:facet name="footer">
				<rich:datascroller renderIfSinglePage="false" reRender="listaVeiculo" />
            </f:facet>

		</rich:dataTable>

	</h:panelGroup>

</ui:composition>